package com.weigee.ktv.presenter.adapter.base

import android.view.LayoutInflater
import android.view.ViewGroup
import com.linde.library.adapter.BaseLvGvAdapter
import com.linde.library.adapter.SimpleViewHolder
import com.weigee.ktv.R
import kotlinx.android.synthetic.main.adapter_recharge_return.view.*

/**
 * Created by linde on 2017/6/8.
 * LinDe
 */
class RechargeReturnAdapter : BaseLvGvAdapter<String>() {
    var selectedItem = -1
        private set

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): SimpleViewHolder {
        val itemView = LayoutInflater.from(parent?.context).inflate(R.layout.adapter_recharge_return, parent, false)
        return SimpleViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: SimpleViewHolder?, position: Int) {
        holder?.let {
            val isSelected = selectedItem == position
            it.itemView.linear_bg.isSelected = isSelected
            it.itemView.tv_recharge_num.isSelected = isSelected
            it.itemView.tv_return_num.isSelected = isSelected

            it.itemView.setOnClickListener {
                selectedItem = if (selectedItem == position) -1 else position
                notifyDataSetChanged()
            }
        }
    }

    override fun getCount(): Int {
//      todo  return super.getCount()
        return 9
    }
}